package com.example.test.controller;


import com.example.test.bean.DTO.input.OrderInputDTO;
import com.example.test.bean.DTO.output.OrderOutputDTO;
import com.example.test.common.model.PageModel;
import com.example.test.common.model.R;
import com.example.test.service.BaseOrdersService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 基础订单表 前端控制器
 * </p>
 *
 * @author dz
 * @since 2022-04-10
 */
@CrossOrigin
@RestController
@RequestMapping("/base-orders")
public class BaseOrdersController {

    @Resource
    private BaseOrdersService baseOrdersService;


    @ApiOperation(value = "根据keyword分页查询")
    @GetMapping("/getByKeyword")
    public R usersList( String keyword, PageModel pageModel) {
        return baseOrdersService.getOrderByKeyword(keyword,pageModel);
    }

    @ApiOperation(value = "根据id分页查询")
    @GetMapping("/getOrder")
    public R listById( Long orderId) {
        return baseOrdersService.getOrder(orderId);
    }

    @ApiOperation(value = "插入订单")
    @PostMapping("/add")
    public R insert( @RequestBody OrderOutputDTO orderOutputDTO) {
        return baseOrdersService.addOrder(orderOutputDTO);
    }

    @ApiOperation(value = "更新订单")
    @PostMapping("/update")
    public R updateOrder(@RequestBody  OrderInputDTO orderInputDTO) {
        return baseOrdersService.updateOrder(orderInputDTO);
    }

    @ApiOperation(value = "完成订单")
    @PostMapping("/finish")
    public R finishOrder(@RequestBody OrderInputDTO orderInputDTO) {
        return baseOrdersService.finishOrder(orderInputDTO);
    }

    @ApiOperation(value = "删除订单")
    @PostMapping("/delete")
    public R deleteOrder( Long orderId) {
        return baseOrdersService.deleteOrder(orderId);
    }

    @ApiOperation(value = "删除订单")
    @GetMapping("/create")
    public R create() {
        return baseOrdersService.createAll();
    }
}

